package com.jingxing.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jingxing.config.ApiResult;
import com.jingxing.service.CodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@RequestMapping("/code")
@Api(value = "API", tags = {"验证码"})
public class CodeController {
    @Autowired
    private CodeService codeService;

    /**
     * 获取验证码
     */
    @PostMapping("/getCode")
    @ApiOperation(value = "获取验证码", response = ApiResult.class)
    public ApiResult<Boolean> getCode(String phone) {
        if (StringUtils.isBlank(phone)) {
            return ApiResult.parameterError("phone不能为空");
        }
        boolean flag = codeService.getCode(phone);
        return ApiResult.result(flag);
    }
}
